package cn.iocoder.yudao.module.eval.service.certificationscheme;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.eval.controller.admin.certificationscheme.vo.*;
import cn.iocoder.yudao.module.eval.dal.dataobject.certificationscheme.CertificationSchemeDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.eval.dal.mysql.certificationscheme.CertificationSchemeMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.eval.enums.ErrorCodeConstants.*;

/**
 * 认定方案表 Service 实现类
 *
 * @author 企业技能认定云平台
 */
@Service
@Validated
public class CertificationSchemeServiceImpl implements CertificationSchemeService {

    @Resource
    private CertificationSchemeMapper certificationSchemeMapper;

    @Override
    public Long createCertificationScheme(CertificationSchemeSaveReqVO createReqVO) {
        // 插入
        CertificationSchemeDO certificationScheme = BeanUtils.toBean(createReqVO, CertificationSchemeDO.class);
        certificationSchemeMapper.insert(certificationScheme);

        // 返回
        return certificationScheme.getId();
    }

    @Override
    public void updateCertificationScheme(CertificationSchemeSaveReqVO updateReqVO) {
        // 校验存在
        validateCertificationSchemeExists(updateReqVO.getId());
        // 更新
        CertificationSchemeDO updateObj = BeanUtils.toBean(updateReqVO, CertificationSchemeDO.class);
        certificationSchemeMapper.updateById(updateObj);
    }

    @Override
    public void deleteCertificationScheme(Long id) {
        // 校验存在
        validateCertificationSchemeExists(id);
        // 删除
        certificationSchemeMapper.deleteById(id);
    }

    @Override
        public void deleteCertificationSchemeListByIds(List<Long> ids) {
        // 删除
        certificationSchemeMapper.deleteByIds(ids);
        }


    private void validateCertificationSchemeExists(Long id) {
        if (certificationSchemeMapper.selectById(id) == null) {
            throw exception(CERTIFICATION_SCHEME_NOT_EXISTS);
        }
    }

    @Override
    public CertificationSchemeDO getCertificationScheme(Long id) {
        return certificationSchemeMapper.selectById(id);
    }

    @Override
    public PageResult<CertificationSchemeDO> getCertificationSchemePage(CertificationSchemePageReqVO pageReqVO) {
        return certificationSchemeMapper.selectPage(pageReqVO);
    }

}